package com.uduew.sjd.view;

import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;

public class CustomProgressDrawable extends LayerDrawable {
    private Drawable mProgressDrawable;
    private Drawable mIconDrawable;

    public CustomProgressDrawable(Drawable icon, Drawable progress) {
        super(new Drawable[]{icon, progress});
        mIconDrawable = icon;
        mProgressDrawable = progress;
    }

    @Override
    public void draw(Canvas canvas) {
        // 先画图标
        mIconDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        mIconDrawable.draw(canvas);
        // 再画进度条（根据你的需求调整进度条的绘制方式）
        mProgressDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        mProgressDrawable.draw(canvas);
    }

    @Override
    public void setAlpha(int alpha) {
        mIconDrawable.setAlpha(alpha);
        mProgressDrawable.setAlpha(alpha);
    }

    @Override
    public void setColorFilter(ColorFilter cf) {
        mIconDrawable.setColorFilter(cf);
        mProgressDrawable.setColorFilter(cf);
    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }
}